
import __builtin__
from client.bulletsystem.testbullet import TestBullet
from panda3d.core import Vec3, VBase3


class BulletManager():
    def __init__(self):
        self.bulletNode = __builtin__.render.attachNewNode("Bullet Node")
        self.bullets = []

    def create_bullet(self, type, start, target, damage):
        new = 0

        if type == "TestBullet":
            new = TestBullet(self, target, damage)

        if new != 0:
            new.bulletNode.reparentTo(self.bulletNode)
            self.bullets.append(new)
            new.bulletNode.setPos(start)

        return new

    def activate(self):
        self.bulletNode.reparentTo(__builtin__.render)

    def deactivate(self):
        self.bulletNode.detachNode()

    def clear(self):
        for t in self.bullets:
            t.remove_node()

        self.bullets = []

    def update(self, dt):
        # update bullets
        for b in self.bullets:
            b.update(dt)